const Base = require('../base.js');


module.exports = class extends Base {
  async indexAction() {
    var db = this.mongoose('mongo/sn_upload'); // 链接数据库
    console.log(this.get('name'))
    var _id = think.objId(this.get('name'));
    console.log(_id)
    var find = await db.find({_id: _id});
    console.log(find)
    if (find.length > 0) {
      await db.update({_id: _id}, {$inc:{visits: 1}});
      this.redirect('/' + find[0].url);
    } else {
      return this.body = 'no files'
    }
  }
  async ossfileAction () {
    var objname = 'test/2019/04/02/sadasdasd.jpg'
    var OSS = this.model('oss').useOSS();
    let url = OSS.signatureUrl(objname , {expires: 3600})
    this.redirect(url);
  }
};
